import { ItemType, SuppliesType } from "../Framework/Const/Constant";
import { DataManager } from "../Framework/Managers/DataManager";
import { ZTool } from "../Framework/Utils/ZTool";

export class PlayerData {
    static MaxBackpackItems: number = 10;

    constructor(Helmet: ItemData = null, Bulletproof: ItemData = null, Weapon_0: ItemData = null, Weapon_1: ItemData = null, Pistol: ItemData = null, MeleeWeapon: ItemData = null, BackpackItems: ItemData[] = []) {
        this.Helmet = Helmet;
        this.Bulletproof = Bulletproof;
        this.Weapon_0 = Weapon_0;
        this.Weapon_1 = Weapon_1;
        this.Pistol = Pistol;
        this.MeleeWeapon = MeleeWeapon;
        this.BackpackItems = BackpackItems;
    }

    Name: string = ``;
    Helmet: ItemData = null;
    Bulletproof: ItemData = null;
    Weapon_0: ItemData = null;
    Weapon_1: ItemData = null;
    Pistol: ItemData = null;
    BackpackItems: ItemData[] = [];

    _MeleeWeapon: ItemData = null;
    public get MeleeWeapon(): ItemData {
        if (this._MeleeWeapon == null) {
            if (DataManager.ItemDatas) {
                this._MeleeWeapon = ZTool.DeepCopy(DataManager.ItemDatas.get(ItemType.近战武器).find(e => e.Name == "M9军刀"));
            }
        }
        return this._MeleeWeapon;
    }
    public set MeleeWeapon(value: ItemData) {
        this._MeleeWeapon = value;
    }

    Clear() {
        this.Helmet = null;
        this.Bulletproof = null;
        this.Weapon_0 = null;
        this.Weapon_1 = null;
        this.Pistol = null;
        this.MeleeWeapon = null;
        this.BackpackItems = [];
    }

    ItemToArray() {
        let items = [];
        this.Helmet && (items.push(this.Helmet));
        this.Bulletproof && (items.push(this.Bulletproof));
        this.Weapon_0 && (items.push(this.Weapon_0));
        this.Weapon_1 && (items.push(this.Weapon_1));
        this.Pistol && (items.push(this.Pistol));
        this.BackpackItems && (items.push(...this.BackpackItems));
        return items;
    }
}

export class ItemData {
    constructor(public Name: string, public Type: string, public Price: number, count: number = -1) {
        if (count == -1 && Type == "子弹") {
            this.Count = 60;
        }
    }

    Count: number = 1;


    //所有主武器的种类
    static MainGunTypes = [ItemType.冲锋枪, ItemType.卡宾枪, ItemType.射手步枪, ItemType.栓动步枪, ItemType.突击步枪, ItemType.轻机枪, ItemType.霰弹枪];

    //所有枪的种类
    static GunTypes = [ItemType.冲锋枪, ItemType.卡宾枪, ItemType.射手步枪, ItemType.栓动步枪, ItemType.突击步枪, ItemType.轻机枪, ItemType.霰弹枪, ItemType.手枪];

    //所有的枪
    static IsGun(type: ItemType) {
        return type == ItemType.冲锋枪 || type == ItemType.卡宾枪 || type == ItemType.射手步枪 || type == ItemType.手枪 || type == ItemType.栓动步枪 || type == ItemType.突击步枪 || type == ItemType.轻机枪 || type == ItemType.霰弹枪;
    }

    //所有的枪
    static IsMeleeWeapon(type: string) {
        return type == ItemType[ItemType.近战武器];
    }

    static IsEquip(type: ItemType) {
        return type == ItemType.头盔 || type == ItemType.防弹衣;
    }

    static IsSniper(type: ItemType) {
        return type == ItemType.卡宾枪 || type == ItemType.射手步枪 || type == ItemType.栓动步枪;
    }

    //是否是药品
    static IsMedicine(type: ItemType) {
        return type == ItemType.药品;
    }

    //所有的枪不包含手枪
    static IsMainGun(type: ItemType) {
        return type == ItemType.冲锋枪 || type == ItemType.卡宾枪 || type == ItemType.射手步枪 || type == ItemType.栓动步枪 || type == ItemType.突击步枪 || type == ItemType.轻机枪 || type == ItemType.霰弹枪;
    }

    static GetScale(type: string) {
        let scale = 1;
        if (type == ItemType[ItemType.头盔]) scale = 0.6;
        if (type == ItemType[ItemType.防弹衣]) scale = 0.6;
        if (type == ItemType[ItemType.手枪]) scale = 0.8;
        if (type == ItemType[ItemType.突击步枪]) scale = 0.8;
        if (type == ItemType[ItemType.冲锋枪]) scale = 0.8;
        if (type == ItemType[ItemType.射手步枪]) scale = 0.8;
        if (type == ItemType[ItemType.栓动步枪]) scale = 0.8;
        if (type == ItemType[ItemType.轻机枪]) scale = 0.8;
        if (type == ItemType[ItemType.霰弹枪]) scale = 0.8;
        if (type == ItemType[ItemType.卡宾枪]) scale = 0.8;
        if (type == ItemType[ItemType.子弹]) scale = 0.6;
        if (type == ItemType[ItemType.战利品]) scale = 0.6;
        if (type == ItemType[ItemType.药品]) scale = 0.6;

        return scale;
    }
}

export class 头盔 extends ItemData {
    constructor(name: string, type: string, price: number, position: string, lv: number) {
        super(name, type, price);
        this.Lv = lv;
        this.Position.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        this.Durability = 100;
    }

    Durability: number = 100;
    Lv: number = 0;
    Position: cc.Vec2 = cc.v2();
}

export class 防弹衣 extends ItemData {
    constructor(name: string, type: string, price: number, position: string, lv: number, count: number = 1) {
        super(name, type, price);
        this.Lv = lv;
        this.Position.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        this.Durability = 100;
    }
    Durability: number = 100;
    Lv: number = 0;
    Position: cc.Vec2 = cc.v2();
}

export class 有甲弹挂 extends ItemData {
    constructor(name: string, type: string, price: number, lv: number) {
        super(name, type, price);
        this.Lv = lv;
    }

    Lv: number = 0;
}

export class 防毒面具 extends ItemData {
    constructor(name: string, type: string, price: number, durability: number) {
        super(name, type, price);
        this.Durability = durability;
    }

    Durability: number = 0;
}

export class 弹挂 extends ItemData {
    constructor(name: string, type: string, price: number) {
        super(name, type, price);
    }
}

export class 背包 extends ItemData {
    constructor(name: string, type: string, price: number, content: number) {
        super(name, type, price);
        this.Content = content;
    }

    Content: number = 0;
}

export class 手枪 extends ItemData {
    constructor(name: string, type: string, price: number, damage: number, fireRate: number, recoil: number, desc: string, position) {
        super(name, type, price);
        this.Damage = damage;
        this.FireRate = fireRate;
        this.Desc = desc;
        this.Recoil = recoil;
        if (typeof position == "string") {
            this.FirePosition.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        } else {
            this.FirePosition.set(position);
        }
    }

    MaxMagazineBulletCount: number = 12;
    MagazineBulletCount: number = 12;//弹夹子弹
    BulletCount: number = 0;//总子弹
    Damage: number = 0;
    FireRate: number = 0;
    Recoil: number = 0;
    Desc: string = "";
    FirePosition: cc.Vec2 = cc.v2();
}

export class 突击步枪 extends ItemData {
    constructor(name: string, type: string, price: number, damage: number, fireRate: number, recoil: number, desc: string, position) {
        super(name, type, price);
        this.Damage = damage;
        this.FireRate = fireRate;
        this.Recoil = recoil;
        this.Desc = desc;
        if (typeof position == "string") {
            this.FirePosition.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        } else {
            this.FirePosition.set(position);
        }
    }

    MaxMagazineBulletCount: number = 30;
    MagazineBulletCount: number = 30;//弹夹子弹
    BulletCount: number = 0;//总子弹
    Damage: number = 0;
    FireRate: number = 0;
    Recoil: number = 0;
    Desc: string = "";
    FirePosition: cc.Vec2 = cc.v2();
}

export class 冲锋枪 extends ItemData {
    constructor(name: string, type: string, price: number, damage: number, fireRate: number, recoil: number, desc: string, position) {
        super(name, type, price);
        this.Damage = damage;
        this.FireRate = fireRate;
        this.Recoil = recoil;
        this.Desc = desc;
        if (typeof position == "string") {
            this.FirePosition.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        } else {
            this.FirePosition.set(position);
        }
    }

    MaxMagazineBulletCount: number = 45;
    MagazineBulletCount: number = 45;//弹夹子弹
    BulletCount: number = 0;//总子弹
    Damage: number = 0;
    FireRate: number = 0;
    Recoil: number = 0;
    Desc: string = "";
    FirePosition: cc.Vec2 = cc.v2();
}

export class 射手步枪 extends ItemData {
    constructor(name: string, type: string, price: number, damage: number, fireRate: number, recoil: number, desc: string, position) {
        super(name, type, price);
        this.Damage = damage;
        this.FireRate = fireRate;
        this.Recoil = recoil;
        this.Desc = desc;
        if (typeof position == "string") {
            this.FirePosition.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        } else {
            this.FirePosition.set(position);
        }
    }

    MaxMagazineBulletCount: number = 20;
    MagazineBulletCount: number = 20;//弹夹子弹
    BulletCount: number = 0;//总子弹
    Damage: number = 0;
    FireRate: number = 0;
    Recoil: number = 0;
    Desc: string = "";
    FirePosition: cc.Vec2 = cc.v2();
}

export class 栓动步枪 extends ItemData {
    constructor(name: string, type: string, price: number, damage: number, fireRate: number, recoil: number, desc: string, position) {
        super(name, type, price);
        this.Damage = damage;
        this.FireRate = fireRate;
        this.Recoil = recoil;
        this.Desc = desc;
        if (typeof position == "string") {
            this.FirePosition.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        } else {
            this.FirePosition.set(position);
        }
    }

    MaxMagazineBulletCount: number = 10;
    MagazineBulletCount: number = 10;//弹夹子弹
    BulletCount: number = 0;//总子弹
    Damage: number = 0;
    FireRate: number = 0;
    Recoil: number = 0;
    Desc: string = "";
    FirePosition: cc.Vec2 = cc.v2();
}

export class 轻机枪 extends ItemData {
    constructor(name: string, type: string, price: number, damage: number, fireRate: number, recoil: number, desc: string, position) {
        super(name, type, price);
        this.Damage = damage;
        this.FireRate = fireRate;
        this.Recoil = recoil;
        this.Desc = desc;
        if (typeof position == "string") {
            this.FirePosition.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        } else {
            this.FirePosition.set(position);
        }
    }

    MaxMagazineBulletCount: number = 100;
    MagazineBulletCount: number = 100;//弹夹子弹
    BulletCount: number = 0;//总子弹
    Damage: number = 0;
    FireRate: number = 0;
    Recoil: number = 0;
    Desc: string = "";
    FirePosition: cc.Vec2 = cc.v2();
}

export class 霰弹枪 extends ItemData {
    constructor(name: string, type: string, price: number, damage: number, fireRate: number, recoil: number, desc: string, position) {
        super(name, type, price);
        this.Damage = damage;
        this.FireRate = fireRate;
        this.Recoil = recoil;
        this.Desc = desc;
        if (typeof position == "string") {
            this.FirePosition.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        } else {
            this.FirePosition.set(position);
        }
    }

    MaxMagazineBulletCount: number = 10;
    MagazineBulletCount: number = 10;//弹夹子弹
    BulletCount: number = 0;//总子弹
    Damage: number = 0;
    FireRate: number = 0;
    Recoil: number = 0;
    Desc: string = "";
    FirePosition: cc.Vec2 = cc.v2();
}

export class 卡宾枪 extends ItemData {
    constructor(name: string, type: string, price: number, damage: number, fireRate: number, recoil: number, desc: string, position) {
        super(name, type, price);
        this.Damage = damage;
        this.FireRate = fireRate;
        this.Recoil = recoil;
        this.Desc = desc;
        if (typeof position == "string") {
            this.FirePosition.set(cc.v2(Number(position.split(`,`)[0]), Number(position.split(`,`)[1])));
        } else {
            this.FirePosition.set(position);
        }
    }

    MaxMagazineBulletCount: number = 15;
    MagazineBulletCount: number = 15;//弹夹子弹
    BulletCount: number = 0;//总子弹
    Damage: number = 0;
    FireRate: number = 0;
    Recoil: number = 0;
    Desc: string = "7.62×39";
    FirePosition: cc.Vec2 = cc.v2();
}

export class 近战武器 extends ItemData {
    constructor(name: string, type: string, price: number, damage: number, fireRate: number) {
        super(name, type, price);
        this.Damage = damage;
        this.FireRate = fireRate;
    }

    Damage: number = 0;
    FireRate: number = 0;
}

export class 子弹 extends ItemData {
    constructor(name: string, type: string, price: number) {
        super(name, type, price);
    }
}

export class 投掷物 extends ItemData {
    constructor(name: string, type: string, price: number, lv: number) {
        super(name, type, price);
    }
}

export class 钥匙 extends ItemData {
    constructor(name: string, type: string, price: number, lv: number) {
        super(name, type, price);
    }
}

export class 药品 extends ItemData {
    constructor(name: string, type: string, price: number, time: number, hp: number) {
        super(name, type, price);
        this.HP = hp;
        this.Time = time;
    }

    HP: number = 0;
    Time: number = 2;
}

export class 食物 extends ItemData {
    constructor(name: string, type: string, price: number, hp: number) {
        super(name, type, price);
        this.HP = hp;
    }

    HP: number = 0;
}

export class 战利品 extends ItemData {
    constructor(name: string, type: string, price: number) {
        super(name, type, price);
    }
}

export class Money extends ItemData {
    constructor(name: string, type: string) {
        super(name, type, 1);
    }
}

//补给
export class SuppliesData {
    //"USP风扇","便携电脑","刨冰机","勘测仪","医用剪刀","医用海绵","千斤顶","喷油器","小霸王","录音带","打字机","打火机","摄像头","收音机",
    //"机油","水壶","洗发水","热成像仪","照相机","狮银币","电影胶卷","眼镜","破碎的屏幕","示波器","胶带","邮票","金杯","金色手机","镜头","隔音棉","音乐盒","颜料",

    static Out: string[][] = [
        //None
        [],
        //保险柜,
        ["金杯", "金色手机", "狮银币", "邮票", "便携电脑", "照相机", "镜头", "隔音棉", "音乐盒", "照相机"],
        //储物盒
        ["USP风扇", "便携电脑", "刨冰机", "勘测仪", "医用剪刀", "镜头", "眼镜", "电影胶卷", "音乐盒", "示波器", "颜料", "胶带", "医用海绵", "隔音棉", "千斤顶", "喷油器", "小霸王", "录音带", "打字机", "打火机", "摄像头", "收音机", "机油", "水壶", "洗发水", "热成像仪", "照相机"],
        //医疗用品
        [],
        //弹药箱
        [],
        //武器箱
        [],
        //电脑
        ["USP风扇", "摄像头", "破碎的屏幕", "示波器"]
    ];

    constructor(name: string, type: SuppliesType, time: number, count: number, needKey: boolean, hasOpenState: boolean) {
        this.Name = name;
        this.Type = type;
        this.Time = time;
        this.Count = count;
        this.NeedKey = needKey;
        this.HasOpenState = hasOpenState;
        this.Taken = false;
        this.PlayerName = '';
    }

    Name: string;
    PlayerName: string = '';
    Type: SuppliesType;
    Time: number;
    Count: number;
    NeedKey: boolean;
    Taken: boolean = false;
    HasOpenState: boolean;
}

//赛季奖励
export class SeasonData {
    constructor(Name_1: string, Name_2: string, Type: string, Count_1: number, Count_2: number, IsJunXu: boolean) {
        this.Count_1 = Count_1;
        this.Count_2 = Count_2;

        if (DataManager.ItemDatas.has(ItemType[`${Type}`])) {
            this.ItemData_1 = ZTool.DeepCopy(DataManager.ItemDatas.get(ItemType[`${Type}`]).find(e => e.Name == Name_1));
            if (this.ItemData_1) this.ItemData_1.Count = Count_1;
        }

        if (IsJunXu) {
            this.ItemData_2 = ZTool.DeepCopy(DataManager.JunXuItems.find(e => e.Name == Name_2));
            if (this.ItemData_2) this.ItemData_2.Count = Count_2;
        } else {
            if (DataManager.ItemDatas.has(ItemType[`${Type}`])) {
                this.ItemData_2 = ZTool.DeepCopy(DataManager.ItemDatas.get(ItemType[`${Type}`]).find(e => e.Name == Name_2));
                if (this.ItemData_2) this.ItemData_2.Count = Count_2;
            }
        }

    }

    Count_1: number = 1;
    Count_2: number = 1;
    ItemData_1: ItemData = null;
    ItemData_2: ItemData = null;
}